﻿namespace TestTool.GUI.Controls.Device
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;
    using TestTool.GUI.Controllers;
    using TestTool.GUI.Controls;
    using TestTool.GUI.Data;
    using TestTool.GUI.Enums;
    using TestTool.GUI.Utils;
    using TestTool.GUI.Views;
    using TestTool.Proxies.Onvif;
    using TestTool.Tests.Common.Media;
    using TestTool.Tests.Common.TestEngine;

    internal class MediaPage : Page, IMediaView, IView
    {
        private MediaController _controller;
        private string _currentAudioEncoder;
        private string _currentVideoEncoder;
        private VideoContainer _videoWindow;
        private Button btnDeleteProfile;
        private Button btnGetMediaUrl;
        private Button btnGetProfiles;
        private Button btnGetStreams;
        private Button buttonGetAudioCodecs;
        private Button buttonGetAudioEncoders;
        private Button buttonGetAudioSources;
        private Button buttonGetVideoCodecs;
        private Button buttonGetVideoEncoders;
        private Button buttonGetVideoSources;
        private ComboBox cmbAudioBitrate;
        private ComboBox cmbAudioCodec;
        private ComboBox cmbAudioEncoder;
        private ComboBox cmbAudioSource;
        private ComboBox cmbMediaProfile;
        private ComboBox cmbTransport;
        private ComboBox cmbVideoCodec;
        private ComboBox cmbVideoEncoder;
        private ComboBox cmbVideoResolution;
        private ComboBox cmbVideoSource;
        private IContainer components;
        private GroupBox gbAudio;
        private GroupBox gbVideo;
        private GroupBox groupProfile;
        private Label label2;
        private Label label3;
        private Label label4;
        private Label label5;
        private Label lblAudioCodec;
        private Label lblAudioEncoder;
        private Label lblAudioSource;
        private Label lblMediaUrl;
        private Label lblVideoCodec;
        private Label lblVideoEncoder;
        private Label lblVideoResolution;
        private Label lblVideoSource;
        private TextBox tbMediaUrl;
        private TextBox tbReport;
        private TextBox txtVideoBitrate;
        private TextBox txtVideoFramerate;

        public MediaPage()
        {
            this.InitializeComponent();
            this._controller = new MediaController(this);
            this.cmbAudioCodec.DisplayMember = "Encoding";
            this.cmbTransport.Items.Add(new TransportProtocolWrapper(TransportProtocol.UDP, "RTP/UDP"));
            this.cmbTransport.Items.Add(new TransportProtocolWrapper(TransportProtocol.RTSP, "RTP/RTSP/TCP"));
            this.cmbTransport.Items.Add(new TransportProtocolWrapper(TransportProtocol.HTTP, "RTP/RTSP/HTTP/TCP"));
            this.cmbTransport.SelectedIndex = 0;
        }

        private void btnGetMediaUrl_Click(object sender, EventArgs e)
        {
            try
            {
                this.Controller.GetMediaAddress();
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
        }

        private void btnGetProfiles_Click(object sender, EventArgs e)
        {
            try
            {
                this._controller.GetMediaProfiles();
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
        }

        private void btnGetStreams_Click(object sender, EventArgs e)
        {
            try
            {
                if (this._videoWindow == null)
                {
                    this.OnPlayVideo();
                }
                else
                {
                    this._videoWindow.CloseWindow();
                    this._videoWindow = null;
                    this.btnGetStreams.Text = "Play Video";
                }
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
        }

        private void buttonGetAudioCodecs_Click(object sender, EventArgs e)
        {
            AudioEncoderConfigurationWrapper selectedItem = this.cmbAudioEncoder.SelectedItem as AudioEncoderConfigurationWrapper;
            if (selectedItem == null)
            {
                base.ShowPrompt("Select audio encoder configuration", "Error");
            }
            else
            {
                try
                {
                    this._controller.GetAudioEncoderConfigOptions(selectedItem.Configuration.token);
                }
                catch (Exception exception)
                {
                    this.ShowError(exception);
                }
            }
        }

        private void buttonGetAudioEncoders_Click(object sender, EventArgs e)
        {
            try
            {
                this._controller.GetAudioEncoderConfigurations();
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
        }

        private void buttonGetAudioSources_Click(object sender, EventArgs e)
        {
            try
            {
                this._controller.GetAudioSourceConfigurations();
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
        }

        private void buttonGetVideoCodecs_Click(object sender, EventArgs e)
        {
            VideoEncoderConfigurationWrapper selectedItem = this.cmbVideoEncoder.SelectedItem as VideoEncoderConfigurationWrapper;
            if (selectedItem == null)
            {
                base.ShowPrompt("Select video encoder configuration", "Error");
            }
            else
            {
                try
                {
                    this._controller.GetVideoEncoderConfigOptions(selectedItem.Configuration.token);
                }
                catch (Exception exception)
                {
                    this.ShowError(exception);
                }
            }
        }

        private void buttonGetVideoEncoders_Click(object sender, EventArgs e)
        {
            try
            {
                this._controller.GetVideoEncoderConfigurations();
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
        }

        private void buttonGetVideoSources_Click(object sender, EventArgs e)
        {
            try
            {
                this._controller.GetVideoSourceConfigurations();
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
        }

        protected void ClearInfo()
        {
            this.cmbAudioCodec.Items.Clear();
            this.cmbAudioEncoder.Items.Clear();
            this.cmbAudioSource.Items.Clear();
            this.cmbVideoCodec.Items.Clear();
            this.cmbVideoEncoder.Items.Clear();
            this.cmbVideoResolution.Items.Clear();
            this.cmbVideoSource.Items.Clear();
            this.cmbMediaProfile.Items.Clear();
            this.cmbAudioBitrate.Items.Clear();
            this.txtVideoBitrate.Text = null;
            this.txtVideoFramerate.Text = null;
        }

        private void cmbAudioCodec_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.cmbAudioBitrate.Items.Clear();
            AudioEncoderConfigurationOption selectedItem = this.cmbAudioCodec.SelectedItem as AudioEncoderConfigurationOption;
            if ((selectedItem != null) && (selectedItem.BitrateList != null))
            {
                foreach (int num in selectedItem.BitrateList)
                {
                    this.cmbAudioBitrate.Items.Add(num);
                }
                if (this.cmbAudioBitrate.Items.Count > 0)
                {
                    this.cmbAudioBitrate.SelectedIndex = 0;
                }
            }
        }

        private void cmbAudioEncoder_SelectedIndexChanged(object sender, EventArgs e)
        {
            AudioEncoderConfigurationWrapper selectedItem = this.cmbAudioEncoder.SelectedItem as AudioEncoderConfigurationWrapper;
            if ((selectedItem == null) || (selectedItem.Configuration.token != this._currentAudioEncoder))
            {
                this._currentAudioEncoder = selectedItem.Configuration.token;
                this.cmbAudioCodec.Items.Clear();
                this.cmbAudioBitrate.Items.Clear();
            }
        }

        private void cmbMediaProfile_SelectedIndexChanged(object sender, EventArgs e)
        {
            TestTool.Proxies.Onvif.Profile profile = ((MediaProfileWrapper)this.cmbMediaProfile.SelectedItem).Profile;
            bool flag = this.IsTestProfile(profile);
            this.cmbAudioCodec.Items.Clear();
            this.cmbAudioEncoder.Items.Clear();
            this.cmbAudioSource.Items.Clear();
            this.cmbVideoCodec.Items.Clear();
            this.cmbVideoEncoder.Items.Clear();
            this.cmbVideoResolution.Items.Clear();
            this.cmbVideoSource.Items.Clear();
            this.cmbAudioBitrate.Items.Clear();
            this.txtVideoBitrate.Text = null;
            this.txtVideoFramerate.Text = null;
            if (!flag)
            {
                if (profile.VideoSourceConfiguration != null)
                {
                    VideoSourceConfigurationWrapper item = new VideoSourceConfigurationWrapper
                    {
                        Configuration = profile.VideoSourceConfiguration
                    };
                    this.cmbVideoSource.Items.Add(item);
                    this.cmbVideoSource.SelectedIndex = 0;
                }
                if (profile.VideoEncoderConfiguration != null)
                {
                    VideoEncoderConfigurationWrapper wrapper2 = new VideoEncoderConfigurationWrapper
                    {
                        Configuration = profile.VideoEncoderConfiguration
                    };
                    this.cmbVideoEncoder.Items.Add(wrapper2);
                    this.cmbVideoEncoder.SelectedIndex = 0;
                    this.cmbVideoCodec.Items.Add(profile.VideoEncoderConfiguration.Encoding);
                    this.cmbVideoCodec.SelectedIndex = 0;
                    VideoResolutionWrapper wrapper3 = new VideoResolutionWrapper
                    {
                        Resolution = profile.VideoEncoderConfiguration.Resolution
                    };
                    this.cmbVideoResolution.Items.Add(wrapper3);
                    this.cmbVideoResolution.SelectedIndex = 0;
                    if (profile.VideoEncoderConfiguration.RateControl != null)
                    {
                        this.txtVideoBitrate.Text = profile.VideoEncoderConfiguration.RateControl.BitrateLimit.ToString();
                        this.txtVideoFramerate.Text = profile.VideoEncoderConfiguration.RateControl.FrameRateLimit.ToString();
                    }
                }
                if (profile.AudioSourceConfiguration != null)
                {
                    AudioSourceConfigurationWrapper wrapper4 = new AudioSourceConfigurationWrapper
                    {
                        Configuration = profile.AudioSourceConfiguration
                    };
                    this.cmbAudioSource.Items.Add(wrapper4);
                    this.cmbAudioSource.SelectedIndex = 0;
                }
                if (profile.AudioEncoderConfiguration != null)
                {
                    AudioEncoderConfigurationWrapper wrapper5 = new AudioEncoderConfigurationWrapper
                    {
                        Configuration = profile.AudioEncoderConfiguration
                    };
                    this.cmbAudioEncoder.Items.Add(wrapper5);
                    this.cmbAudioEncoder.SelectedIndex = 0;
                    this.cmbAudioCodec.Items.Add(profile.AudioEncoderConfiguration.Encoding);
                    this.cmbAudioCodec.SelectedIndex = 0;
                    this.cmbAudioBitrate.Items.Add(profile.AudioEncoderConfiguration.Bitrate);
                    this.cmbAudioBitrate.SelectedIndex = 0;
                }
            }
            this.EnableControls(true);
        }

        private void cmbVideoCodec_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.cmbVideoResolution.Items.Clear();
            this.txtVideoBitrate.Text = null;
            this.txtVideoFramerate.Text = null;
            VideoCodecWrapper selectedItem = this.cmbVideoCodec.SelectedItem as VideoCodecWrapper;
            if (selectedItem != null)
            {
                VideoResolution[] resolutions = selectedItem.GetResolutions();
                if (resolutions != null)
                {
                    foreach (VideoResolution resolution in resolutions)
                    {
                        VideoResolutionWrapper item = new VideoResolutionWrapper
                        {
                            Resolution = resolution
                        };
                        this.cmbVideoResolution.Items.Add(item);
                    }
                }
                IntRange frameLimit = selectedItem.GetFrameLimit();
                if (frameLimit != null)
                {
                    this.txtVideoFramerate.Text = frameLimit.Min.ToString();
                }
            }
            if (this.cmbVideoResolution.Items.Count > 0)
            {
                this.cmbVideoResolution.SelectedIndex = 0;
            }
        }

        private void cmbVideoEncoder_SelectedIndexChanged(object sender, EventArgs e)
        {
            VideoEncoderConfigurationWrapper selectedItem = this.cmbVideoEncoder.SelectedItem as VideoEncoderConfigurationWrapper;
            if ((selectedItem == null) || (selectedItem.Configuration.token != this._currentVideoEncoder))
            {
                this._currentVideoEncoder = selectedItem.Configuration.token;
                this.cmbVideoCodec.Items.Clear();
                this.cmbVideoResolution.Items.Clear();
                this.txtVideoBitrate.Text = null;
                this.txtVideoFramerate.Text = null;
                this.btnGetStreams.Enabled = this._videoWindow != null;
            }
        }

        public void DisplayLog(string logEntry)
        {
            base.BeginInvoke(new Action(() => this.tbReport.Text = logEntry));
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public void EnableControls(bool enable)
        {
            base.Invoke((Action)delegate
           {
               DiscoveredDevices discoveredDevices = ContextController.GetDiscoveredDevices();
               string str = (discoveredDevices != null) ? discoveredDevices.ServiceAddress : string.Empty;
               bool flag = false;
               if (this.cmbMediaProfile.SelectedItem != null)
               {
                   flag = this.IsTestProfile(((MediaProfileWrapper)this.cmbMediaProfile.SelectedItem).Profile);
               }
               this.btnGetMediaUrl.Enabled = enable && !string.IsNullOrEmpty(str);
               this.btnGetMediaUrl.Refresh();
               this.btnGetProfiles.Enabled = enable && !string.IsNullOrEmpty(this.MediaAddress);
               this.btnGetProfiles.Refresh();
               this.btnDeleteProfile.Enabled = enable && flag;
               this.btnDeleteProfile.Refresh();
               this.buttonGetVideoSources.Enabled = (flag && enable) && !string.IsNullOrEmpty(this.MediaAddress);
               this.buttonGetVideoSources.Refresh();
               this.buttonGetVideoEncoders.Enabled = (flag && enable) && !string.IsNullOrEmpty(this.MediaAddress);
               this.buttonGetVideoEncoders.Refresh();
               this.buttonGetVideoCodecs.Enabled = this.buttonGetVideoEncoders.Enabled && (this.cmbVideoEncoder.SelectedItem != null);
               this.buttonGetVideoCodecs.Refresh();
               this.buttonGetAudioSources.Enabled = (flag && enable) && !string.IsNullOrEmpty(this.MediaAddress);
               this.buttonGetAudioSources.Refresh();
               this.buttonGetAudioEncoders.Enabled = (flag && enable) && !string.IsNullOrEmpty(this.MediaAddress);
               this.buttonGetAudioEncoders.Refresh();
               this.buttonGetAudioCodecs.Enabled = this.buttonGetAudioEncoders.Enabled && (this.cmbAudioEncoder.SelectedItem != null);
               this.buttonGetAudioCodecs.Refresh();
               this.btnGetStreams.Enabled = (enable && (this.cmbVideoResolution.SelectedItem != null)) || (this._videoWindow != null);
               this.cmbMediaProfile.Enabled = enable;
               this.cmbAudioCodec.Enabled = flag && enable;
               this.cmbAudioEncoder.Enabled = flag && enable;
               this.cmbAudioSource.Enabled = flag && enable;
               this.cmbVideoCodec.Enabled = flag && enable;
               this.cmbVideoEncoder.Enabled = flag && enable;
               this.cmbVideoResolution.Enabled = flag && enable;
               this.txtVideoBitrate.Enabled = (flag && enable) && (this.cmbVideoCodec.SelectedItem != null);
               this.txtVideoFramerate.Enabled = (flag && enable) && (this.cmbVideoCodec.SelectedItem != null);
               this.cmbVideoSource.Enabled = flag && enable;
               this.cmbAudioBitrate.Enabled = flag && enable;
               this.cmbTransport.Enabled = flag && enable;
               this.btnGetStreams.Refresh();
           });
        }

        public override IController GetController()
        {
            return this._controller;
        }

        private TransportProtocol GetTransportProtocol()
        {
            TransportProtocol protocol = TransportProtocol.UDP;
            base.Invoke((Action)delegate
            {
                protocol = (TransportProtocol)((TransportProtocolWrapper)this.cmbTransport.SelectedItem);
            });
            return protocol;
        }

        private void InitializeComponent()
        {
            this.gbAudio = new GroupBox();
            this.cmbAudioBitrate = new ComboBox();
            this.label5 = new Label();
            this.buttonGetAudioCodecs = new Button();
            this.buttonGetAudioEncoders = new Button();
            this.buttonGetAudioSources = new Button();
            this.cmbAudioCodec = new ComboBox();
            this.lblAudioCodec = new Label();
            this.cmbAudioEncoder = new ComboBox();
            this.lblAudioEncoder = new Label();
            this.cmbAudioSource = new ComboBox();
            this.lblAudioSource = new Label();
            this.gbVideo = new GroupBox();
            this.txtVideoFramerate = new TextBox();
            this.txtVideoBitrate = new TextBox();
            this.label3 = new Label();
            this.label2 = new Label();
            this.buttonGetVideoCodecs = new Button();
            this.buttonGetVideoEncoders = new Button();
            this.buttonGetVideoSources = new Button();
            this.cmbVideoResolution = new ComboBox();
            this.lblVideoResolution = new Label();
            this.cmbVideoCodec = new ComboBox();
            this.lblVideoCodec = new Label();
            this.cmbVideoEncoder = new ComboBox();
            this.lblVideoEncoder = new Label();
            this.cmbVideoSource = new ComboBox();
            this.lblVideoSource = new Label();
            this.btnGetStreams = new Button();
            this.btnGetMediaUrl = new Button();
            this.tbReport = new TextBox();
            this.tbMediaUrl = new TextBox();
            this.lblMediaUrl = new Label();
            this.groupProfile = new GroupBox();
            this.btnDeleteProfile = new Button();
            this.btnGetProfiles = new Button();
            this.cmbMediaProfile = new ComboBox();
            this.cmbTransport = new ComboBox();
            this.label4 = new Label();
            this.gbAudio.SuspendLayout();
            this.gbVideo.SuspendLayout();
            this.groupProfile.SuspendLayout();
            base.SuspendLayout();
            this.gbAudio.Controls.Add(this.cmbAudioBitrate);
            this.gbAudio.Controls.Add(this.label5);
            this.gbAudio.Controls.Add(this.buttonGetAudioCodecs);
            this.gbAudio.Controls.Add(this.buttonGetAudioEncoders);
            this.gbAudio.Controls.Add(this.buttonGetAudioSources);
            this.gbAudio.Controls.Add(this.cmbAudioCodec);
            this.gbAudio.Controls.Add(this.lblAudioCodec);
            this.gbAudio.Controls.Add(this.cmbAudioEncoder);
            this.gbAudio.Controls.Add(this.lblAudioEncoder);
            this.gbAudio.Controls.Add(this.cmbAudioSource);
            this.gbAudio.Controls.Add(this.lblAudioSource);
            this.gbAudio.Location = new Point(6, 240);
            this.gbAudio.Name = "gbAudio";
            this.gbAudio.Size = new Size(0x169, 0x83);
            this.gbAudio.TabIndex = 0x11;
            this.gbAudio.TabStop = false;
            this.gbAudio.Text = "Audio";
            this.cmbAudioBitrate.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbAudioBitrate.FormattingEnabled = true;
            this.cmbAudioBitrate.Location = new Point(120, 100);
            this.cmbAudioBitrate.Name = "cmbAudioBitrate";
            this.cmbAudioBitrate.Size = new Size(0x5d, 0x15);
            this.cmbAudioBitrate.TabIndex = 0x18;
            this.label5.AutoSize = true;
            this.label5.Location = new Point(6, 100);
            this.label5.Name = "label5";
            this.label5.Size = new Size(40, 13);
            this.label5.TabIndex = 0x38;
            this.label5.Text = "Bitrate:";
            this.buttonGetAudioCodecs.Location = new Point(0x115, 0x47);
            this.buttonGetAudioCodecs.Name = "buttonGetAudioCodecs";
            this.buttonGetAudioCodecs.Size = new Size(0x39, 0x17);
            this.buttonGetAudioCodecs.TabIndex = 0x17;
            this.buttonGetAudioCodecs.Text = "Get";
            this.buttonGetAudioCodecs.UseVisualStyleBackColor = true;
            this.buttonGetAudioCodecs.Click += new EventHandler(this.buttonGetAudioCodecs_Click);
            this.buttonGetAudioEncoders.Location = new Point(0x115, 0x2c);
            this.buttonGetAudioEncoders.Name = "buttonGetAudioEncoders";
            this.buttonGetAudioEncoders.Size = new Size(0x39, 0x17);
            this.buttonGetAudioEncoders.TabIndex = 0x15;
            this.buttonGetAudioEncoders.Text = "Get";
            this.buttonGetAudioEncoders.UseVisualStyleBackColor = true;
            this.buttonGetAudioEncoders.Click += new EventHandler(this.buttonGetAudioEncoders_Click);
            this.buttonGetAudioSources.Location = new Point(0x115, 0x11);
            this.buttonGetAudioSources.Name = "buttonGetAudioSources";
            this.buttonGetAudioSources.Size = new Size(0x39, 0x17);
            this.buttonGetAudioSources.TabIndex = 0x13;
            this.buttonGetAudioSources.Text = "Get";
            this.buttonGetAudioSources.UseVisualStyleBackColor = true;
            this.buttonGetAudioSources.Click += new EventHandler(this.buttonGetAudioSources_Click);
            this.cmbAudioCodec.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbAudioCodec.FormattingEnabled = true;
            this.cmbAudioCodec.Location = new Point(120, 0x49);
            this.cmbAudioCodec.Name = "cmbAudioCodec";
            this.cmbAudioCodec.Size = new Size(0x8e, 0x15);
            this.cmbAudioCodec.TabIndex = 0x16;
            this.cmbAudioCodec.SelectedIndexChanged += new EventHandler(this.cmbAudioCodec_SelectedIndexChanged);
            this.lblAudioCodec.AutoSize = true;
            this.lblAudioCodec.Location = new Point(6, 0x4c);
            this.lblAudioCodec.Name = "lblAudioCodec";
            this.lblAudioCodec.Size = new Size(0x29, 13);
            this.lblAudioCodec.TabIndex = 0x34;
            this.lblAudioCodec.Text = "Codec:";
            this.cmbAudioEncoder.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbAudioEncoder.FormattingEnabled = true;
            this.cmbAudioEncoder.Location = new Point(120, 0x2e);
            this.cmbAudioEncoder.Name = "cmbAudioEncoder";
            this.cmbAudioEncoder.Size = new Size(0x8e, 0x15);
            this.cmbAudioEncoder.TabIndex = 20;
            this.cmbAudioEncoder.SelectedIndexChanged += new EventHandler(this.cmbAudioEncoder_SelectedIndexChanged);
            this.lblAudioEncoder.AutoSize = true;
            this.lblAudioEncoder.Location = new Point(6, 0x31);
            this.lblAudioEncoder.Name = "lblAudioEncoder";
            this.lblAudioEncoder.Size = new Size(0x72, 13);
            this.lblAudioEncoder.TabIndex = 50;
            this.lblAudioEncoder.Text = "Encoder configuration:";
            this.cmbAudioSource.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbAudioSource.FormattingEnabled = true;
            this.cmbAudioSource.Location = new Point(120, 0x13);
            this.cmbAudioSource.Name = "cmbAudioSource";
            this.cmbAudioSource.Size = new Size(0x8e, 0x15);
            this.cmbAudioSource.TabIndex = 0x12;
            this.lblAudioSource.AutoSize = true;
            this.lblAudioSource.Location = new Point(6, 0x16);
            this.lblAudioSource.Name = "lblAudioSource";
            this.lblAudioSource.Size = new Size(0x6c, 13);
            this.lblAudioSource.TabIndex = 0x30;
            this.lblAudioSource.Text = "Source configuration:";
            this.gbVideo.Controls.Add(this.txtVideoFramerate);
            this.gbVideo.Controls.Add(this.txtVideoBitrate);
            this.gbVideo.Controls.Add(this.label3);
            this.gbVideo.Controls.Add(this.label2);
            this.gbVideo.Controls.Add(this.buttonGetVideoCodecs);
            this.gbVideo.Controls.Add(this.buttonGetVideoEncoders);
            this.gbVideo.Controls.Add(this.buttonGetVideoSources);
            this.gbVideo.Controls.Add(this.cmbVideoResolution);
            this.gbVideo.Controls.Add(this.lblVideoResolution);
            this.gbVideo.Controls.Add(this.cmbVideoCodec);
            this.gbVideo.Controls.Add(this.lblVideoCodec);
            this.gbVideo.Controls.Add(this.cmbVideoEncoder);
            this.gbVideo.Controls.Add(this.lblVideoEncoder);
            this.gbVideo.Controls.Add(this.cmbVideoSource);
            this.gbVideo.Controls.Add(this.lblVideoSource);
            this.gbVideo.Location = new Point(6, 0x51);
            this.gbVideo.Name = "gbVideo";
            this.gbVideo.Size = new Size(0x169, 0x99);
            this.gbVideo.TabIndex = 7;
            this.gbVideo.TabStop = false;
            this.gbVideo.Text = "Video";
            this.txtVideoFramerate.Location = new Point(0xdf, 120);
            this.txtVideoFramerate.Name = "txtVideoFramerate";
            this.txtVideoFramerate.Size = new Size(0x5d, 20);
            this.txtVideoFramerate.TabIndex = 0x10;
            this.txtVideoFramerate.Validating += new CancelEventHandler(this.txtVideoFramerate_Validating);
            this.txtVideoBitrate.Location = new Point(0x72, 120);
            this.txtVideoBitrate.Name = "txtVideoBitrate";
            this.txtVideoBitrate.Size = new Size(0x5d, 20);
            this.txtVideoBitrate.TabIndex = 15;
            this.txtVideoBitrate.Validating += new CancelEventHandler(this.txtVideoBitrate_Validating);
            this.label3.AutoSize = true;
            this.label3.Location = new Point(0xdf, 0x68);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x4d, 13);
            this.label3.TabIndex = 0x38;
            this.label3.Text = "Framerate limit:";
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0x72, 0x68);
            this.label2.Name = "label2";
            this.label2.Size = new Size(60, 13);
            this.label2.TabIndex = 0x37;
            this.label2.Text = "Bitrate limit:";
            this.buttonGetVideoCodecs.Location = new Point(0x115, 0x49);
            this.buttonGetVideoCodecs.Name = "buttonGetVideoCodecs";
            this.buttonGetVideoCodecs.Size = new Size(0x39, 0x17);
            this.buttonGetVideoCodecs.TabIndex = 13;
            this.buttonGetVideoCodecs.Text = "Get";
            this.buttonGetVideoCodecs.UseVisualStyleBackColor = true;
            this.buttonGetVideoCodecs.Click += new EventHandler(this.buttonGetVideoCodecs_Click);
            this.buttonGetVideoEncoders.Location = new Point(0x115, 0x2d);
            this.buttonGetVideoEncoders.Name = "buttonGetVideoEncoders";
            this.buttonGetVideoEncoders.Size = new Size(0x39, 0x17);
            this.buttonGetVideoEncoders.TabIndex = 11;
            this.buttonGetVideoEncoders.Text = "Get";
            this.buttonGetVideoEncoders.UseVisualStyleBackColor = true;
            this.buttonGetVideoEncoders.Click += new EventHandler(this.buttonGetVideoEncoders_Click);
            this.buttonGetVideoSources.Location = new Point(0x115, 0x13);
            this.buttonGetVideoSources.Name = "buttonGetVideoSources";
            this.buttonGetVideoSources.Size = new Size(0x39, 0x17);
            this.buttonGetVideoSources.TabIndex = 9;
            this.buttonGetVideoSources.Text = "Get";
            this.buttonGetVideoSources.UseVisualStyleBackColor = true;
            this.buttonGetVideoSources.Click += new EventHandler(this.buttonGetVideoSources_Click);
            this.cmbVideoResolution.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbVideoResolution.FormattingEnabled = true;
            this.cmbVideoResolution.Location = new Point(6, 120);
            this.cmbVideoResolution.Name = "cmbVideoResolution";
            this.cmbVideoResolution.Size = new Size(0x5d, 0x15);
            this.cmbVideoResolution.TabIndex = 14;
            this.lblVideoResolution.AutoSize = true;
            this.lblVideoResolution.Location = new Point(6, 0x69);
            this.lblVideoResolution.Name = "lblVideoResolution";
            this.lblVideoResolution.Size = new Size(60, 13);
            this.lblVideoResolution.TabIndex = 0x36;
            this.lblVideoResolution.Text = "Resolution:";
            this.cmbVideoCodec.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbVideoCodec.FormattingEnabled = true;
            this.cmbVideoCodec.Location = new Point(120, 0x4c);
            this.cmbVideoCodec.Name = "cmbVideoCodec";
            this.cmbVideoCodec.Size = new Size(0x8e, 0x15);
            this.cmbVideoCodec.TabIndex = 12;
            this.cmbVideoCodec.SelectedIndexChanged += new EventHandler(this.cmbVideoCodec_SelectedIndexChanged);
            this.lblVideoCodec.AutoSize = true;
            this.lblVideoCodec.Location = new Point(6, 0x4c);
            this.lblVideoCodec.Name = "lblVideoCodec";
            this.lblVideoCodec.Size = new Size(0x29, 13);
            this.lblVideoCodec.TabIndex = 0x34;
            this.lblVideoCodec.Text = "Codec:";
            this.cmbVideoEncoder.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbVideoEncoder.FormattingEnabled = true;
            this.cmbVideoEncoder.Location = new Point(120, 0x31);
            this.cmbVideoEncoder.Name = "cmbVideoEncoder";
            this.cmbVideoEncoder.Size = new Size(0x8e, 0x15);
            this.cmbVideoEncoder.TabIndex = 10;
            this.cmbVideoEncoder.SelectedIndexChanged += new EventHandler(this.cmbVideoEncoder_SelectedIndexChanged);
            this.lblVideoEncoder.AutoSize = true;
            this.lblVideoEncoder.Location = new Point(6, 50);
            this.lblVideoEncoder.Name = "lblVideoEncoder";
            this.lblVideoEncoder.Size = new Size(0x72, 13);
            this.lblVideoEncoder.TabIndex = 50;
            this.lblVideoEncoder.Text = "Encoder configuration:";
            this.cmbVideoSource.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbVideoSource.FormattingEnabled = true;
            this.cmbVideoSource.Location = new Point(120, 0x15);
            this.cmbVideoSource.Name = "cmbVideoSource";
            this.cmbVideoSource.Size = new Size(0x8e, 0x15);
            this.cmbVideoSource.TabIndex = 6;
            this.lblVideoSource.AutoSize = true;
            this.lblVideoSource.Location = new Point(6, 0x16);
            this.lblVideoSource.Name = "lblVideoSource";
            this.lblVideoSource.Size = new Size(0x6c, 13);
            this.lblVideoSource.TabIndex = 0x30;
            this.lblVideoSource.Text = "Source configuration:";
            this.btnGetStreams.Location = new Point(0x107, 0x178);
            this.btnGetStreams.Name = "btnGetStreams";
            this.btnGetStreams.RightToLeft = RightToLeft.Yes;
            this.btnGetStreams.Size = new Size(0x4d, 0x17);
            this.btnGetStreams.TabIndex = 0x1a;
            this.btnGetStreams.Text = "Play Video";
            this.btnGetStreams.UseVisualStyleBackColor = true;
            this.btnGetStreams.Click += new EventHandler(this.btnGetStreams_Click);
            this.btnGetMediaUrl.Location = new Point(0x139, 4);
            this.btnGetMediaUrl.Name = "btnGetMediaUrl";
            this.btnGetMediaUrl.Size = new Size(0x34, 0x17);
            this.btnGetMediaUrl.TabIndex = 2;
            this.btnGetMediaUrl.Text = "Get ";
            this.btnGetMediaUrl.UseVisualStyleBackColor = true;
            this.btnGetMediaUrl.Click += new EventHandler(this.btnGetMediaUrl_Click);
            this.tbReport.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.tbReport.Location = new Point(0x173, 4);
            this.tbReport.Multiline = true;
            this.tbReport.Name = "tbReport";
            this.tbReport.ReadOnly = true;
            this.tbReport.ScrollBars = ScrollBars.Both;
            this.tbReport.Size = new Size(0x18c, 0x1e6);
            this.tbReport.TabIndex = 0x1b;
            this.tbMediaUrl.Location = new Point(0x45, 4);
            this.tbMediaUrl.Name = "tbMediaUrl";
            this.tbMediaUrl.ReadOnly = true;
            this.tbMediaUrl.Size = new Size(0xee, 20);
            this.tbMediaUrl.TabIndex = 1;
            this.lblMediaUrl.AutoSize = true;
            this.lblMediaUrl.Location = new Point(4, 7);
            this.lblMediaUrl.Name = "lblMediaUrl";
            this.lblMediaUrl.Size = new Size(0x40, 13);
            this.lblMediaUrl.TabIndex = 0x34;
            this.lblMediaUrl.Text = "Media URL:";
            this.groupProfile.Controls.Add(this.btnDeleteProfile);
            this.groupProfile.Controls.Add(this.btnGetProfiles);
            this.groupProfile.Controls.Add(this.cmbMediaProfile);
            this.groupProfile.Location = new Point(6, 0x21);
            this.groupProfile.Name = "groupProfile";
            this.groupProfile.Size = new Size(0x169, 0x2c);
            this.groupProfile.TabIndex = 3;
            this.groupProfile.TabStop = false;
            this.groupProfile.Text = "Media Profile";
            this.btnDeleteProfile.Location = new Point(0xbd, 15);
            this.btnDeleteProfile.Name = "btnDeleteProfile";
            this.btnDeleteProfile.Size = new Size(0x39, 0x17);
            this.btnDeleteProfile.TabIndex = 6;
            this.btnDeleteProfile.Text = "Delete";
            this.btnDeleteProfile.UseVisualStyleBackColor = true;
            this.btnDeleteProfile.Visible = false;
            this.btnGetProfiles.Location = new Point(0xde, 14);
            this.btnGetProfiles.Name = "btnGetProfiles";
            this.btnGetProfiles.Size = new Size(0x39, 0x17);
            this.btnGetProfiles.TabIndex = 5;
            this.btnGetProfiles.Text = "Get";
            this.btnGetProfiles.UseVisualStyleBackColor = true;
            this.btnGetProfiles.Click += new EventHandler(this.btnGetProfiles_Click);
            this.cmbMediaProfile.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbMediaProfile.FormattingEnabled = true;
            this.cmbMediaProfile.Location = new Point(9, 15);
            this.cmbMediaProfile.Name = "cmbMediaProfile";
            this.cmbMediaProfile.Size = new Size(200, 0x15);
            this.cmbMediaProfile.TabIndex = 4;
            this.cmbMediaProfile.SelectedIndexChanged += new EventHandler(this.cmbMediaProfile_SelectedIndexChanged);
            this.cmbTransport.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbTransport.FormattingEnabled = true;
            this.cmbTransport.Location = new Point(0x40, 0x17a);
            this.cmbTransport.Name = "cmbTransport";
            this.cmbTransport.Size = new Size(0xb8, 0x15);
            this.cmbTransport.TabIndex = 0x19;
            this.label4.AutoSize = true;
            this.label4.Location = new Point(3, 0x17d);
            this.label4.Name = "label4";
            this.label4.Size = new Size(0x37, 13);
            this.label4.TabIndex = 0x37;
            this.label4.Text = "Transport:";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.label4);
            base.Controls.Add(this.cmbTransport);
            base.Controls.Add(this.groupProfile);
            base.Controls.Add(this.gbAudio);
            base.Controls.Add(this.btnGetStreams);
            base.Controls.Add(this.gbVideo);
            base.Controls.Add(this.btnGetMediaUrl);
            base.Controls.Add(this.tbReport);
            base.Controls.Add(this.tbMediaUrl);
            base.Controls.Add(this.lblMediaUrl);
            base.Name = "MediaPage";
            base.Size = new Size(0x307, 0x1f0);
            this.gbAudio.ResumeLayout(false);
            this.gbAudio.PerformLayout();
            this.gbVideo.ResumeLayout(false);
            this.gbVideo.PerformLayout();
            this.groupProfile.ResumeLayout(false);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        protected bool IsTestProfile(TestTool.Proxies.Onvif.Profile profile)
        {
            return (profile.Name == "TestMediaProfile");
        }

        private void OnPlayVideo()
        {
            MediaProfileWrapper selectedItem = this.cmbMediaProfile.SelectedItem as MediaProfileWrapper;
            if (selectedItem != null)
            {
                VideoSourceConfigurationWrapper wrapper2 = this.cmbVideoSource.SelectedItem as VideoSourceConfigurationWrapper;
                VideoEncoderConfigurationWrapper wrapper3 = this.cmbVideoEncoder.SelectedItem as VideoEncoderConfigurationWrapper;
                AudioSourceConfigurationWrapper wrapper4 = this.cmbAudioSource.SelectedItem as AudioSourceConfigurationWrapper;
                AudioEncoderConfigurationWrapper wrapper5 = this.cmbAudioEncoder.SelectedItem as AudioEncoderConfigurationWrapper;
                TransportProtocol transportProtocol = this.GetTransportProtocol();
                if ((wrapper2 != null) && (wrapper3 != null))
                {
                    if (this.IsTestProfile(selectedItem.Profile))
                    {
                        VideoCodecWrapper wrapper6 = this.cmbVideoCodec.SelectedItem as VideoCodecWrapper;
                        VideoResolutionWrapper wrapper7 = this.cmbVideoResolution.SelectedItem as VideoResolutionWrapper;
                        int? framerate = null;
                        if (!string.IsNullOrEmpty(this.txtVideoFramerate.Text))
                        {
                            framerate = new int?(int.Parse(this.txtVideoFramerate.Text));
                        }
                        int? bitrate = null;
                        if (!string.IsNullOrEmpty(this.txtVideoBitrate.Text))
                        {
                            bitrate = new int?(int.Parse(this.txtVideoBitrate.Text));
                        }
                        if (wrapper6.Encoding == VideoEncoding.H264)
                        {
                            this.SetH264Configuration(wrapper3.Configuration, wrapper6.H264, wrapper7.Resolution, framerate, bitrate);
                        }
                        else if (wrapper6.Encoding == VideoEncoding.JPEG)
                        {
                            this.SetJPEGConfiguration(wrapper3.Configuration, wrapper6.Jpeg, wrapper7.Resolution, framerate, bitrate);
                        }
                        else if (wrapper6.Encoding == VideoEncoding.MPEG4)
                        {
                            this.SetMPEG4Configuration(wrapper3.Configuration, wrapper6.Mpeg4, wrapper7.Resolution, framerate, bitrate);
                        }
                        if ((wrapper5 != null) && (wrapper5.Configuration != null))
                        {
                            AudioEncoderConfigurationOption options = this.cmbAudioCodec.SelectedItem as AudioEncoderConfigurationOption;
                            if (options != null)
                            {
                                this.SetAudioConfiguration(wrapper5.Configuration, options);
                            }
                        }
                        this.Controller.GetMediaUri((selectedItem.Profile.token != null) ? selectedItem.Profile : null, wrapper2.Configuration, wrapper3.Configuration, (wrapper4 != null) ? wrapper4.Configuration : null, (wrapper5 != null) ? wrapper5.Configuration : null, transportProtocol);
                    }
                    else
                    {
                        this.Controller.GetMediaUri(selectedItem.Profile, transportProtocol);
                    }
                }
                else
                {
                    base.ShowPrompt("Select video source and encoder configuration", "Error");
                }
            }
            else
            {
                base.ShowPrompt("Select media profile", "Error");
            }
        }

        private void SetAudioConfiguration(AudioEncoderConfiguration config, AudioEncoderConfigurationOption options)
        {
            config.Encoding = options.Encoding;
            if (this.cmbAudioBitrate.SelectedItem != null)
            {
                config.Bitrate = (int)this.cmbAudioBitrate.SelectedItem;
            }
            else if ((options.BitrateList != null) && (options.BitrateList.Length > 0))
            {
                config.Bitrate = options.BitrateList[0];
            }
            if ((options.SampleRateList != null) && (options.SampleRateList.Length > 0))
            {
                config.SampleRate = options.SampleRateList[0];
            }
        }

        public void SetAudioEncoderConfigOptions(AudioEncoderConfigurationOptions options)
        {
            base.BeginInvoke((Action)delegate
            {
                this.cmbAudioCodec.Items.Clear();
                foreach (AudioEncoderConfigurationOption option in options.Options)
                {
                    this.cmbAudioCodec.Items.Add(option);
                }
                if (this.cmbAudioCodec.Items.Count > 0)
                {
                    this.cmbAudioCodec.SelectedIndex = 0;
                }
            });
        }

        public void SetAudioEncoderConfigs(AudioEncoderConfiguration[] configs)
        {
            base.BeginInvoke((Action)delegate
            {
                this.cmbAudioEncoder.Items.Clear();
                foreach (AudioEncoderConfiguration configuration in configs)
                {
                    AudioEncoderConfigurationWrapper item = new AudioEncoderConfigurationWrapper
                    {
                        Configuration = configuration
                    };
                    this.cmbAudioEncoder.Items.Add(item);
                }
                if (this.cmbAudioEncoder.Items.Count > 0)
                {
                    this.cmbAudioEncoder.SelectedIndex = 0;
                }
            });
        }

        public void SetAudioSourceConfigs(AudioSourceConfiguration[] configs)
        {
            base.BeginInvoke((Action)delegate
            {
                this.cmbAudioSource.Items.Clear();
                foreach (AudioSourceConfiguration configuration in configs)
                {
                    AudioSourceConfigurationWrapper item = new AudioSourceConfigurationWrapper
                    {
                        Configuration = configuration
                    };
                    this.cmbAudioSource.Items.Add(item);
                }
                if (this.cmbAudioSource.Items.Count > 0)
                {
                    this.cmbAudioSource.SelectedIndex = 0;
                }
            });
        }

        private void SetH264Configuration(VideoEncoderConfiguration config, H264Options options, VideoResolution resolution, int? framerate, int? bitrate)
        {
            config.Encoding = VideoEncoding.H264;
            config.H264 = new H264Configuration();
            config.H264.GovLength = (options.GovLengthRange.Max < 30) ? options.GovLengthRange.Max : 30;
            if (config.H264.GovLength < options.GovLengthRange.Min)
            {
                config.H264.GovLength = options.GovLengthRange.Min;
            }
            if (options.H264ProfilesSupported.Length > 0)
            {
                config.H264.H264Profile = options.H264ProfilesSupported[0];
            }
            if ((config.RateControl == null) && (framerate.HasValue || bitrate.HasValue))
            {
                config.RateControl = new VideoRateControl();
            }
            if (config.RateControl != null)
            {
                config.RateControl.FrameRateLimit = framerate.HasValue ? framerate.Value : options.FrameRateRange.Max;
                config.RateControl.EncodingInterval = options.EncodingIntervalRange.Min;
                if (bitrate.HasValue)
                {
                    config.RateControl.BitrateLimit = bitrate.Value;
                }
            }
            config.Resolution = resolution;
        }

        private void SetJPEGConfiguration(VideoEncoderConfiguration config, JpegOptions options, VideoResolution resolution, int? framerate, int? bitrate)
        {
            config.Encoding = VideoEncoding.JPEG;
            if ((config.RateControl == null) && (framerate.HasValue || bitrate.HasValue))
            {
                config.RateControl = new VideoRateControl();
            }
            if (config.RateControl != null)
            {
                config.RateControl.FrameRateLimit = framerate.HasValue ? framerate.Value : options.FrameRateRange.Max;
                config.RateControl.EncodingInterval = options.EncodingIntervalRange.Min;
                if (bitrate.HasValue)
                {
                    config.RateControl.BitrateLimit = bitrate.Value;
                }
            }
            config.Resolution = resolution;
        }

        private void SetMPEG4Configuration(VideoEncoderConfiguration config, Mpeg4Options options, VideoResolution resolution, int? framerate, int? bitrate)
        {
            config.Encoding = VideoEncoding.MPEG4;
            config.MPEG4 = new Mpeg4Configuration();
            config.MPEG4.GovLength = (options.GovLengthRange.Max < 30) ? options.GovLengthRange.Max : 30;
            if (config.MPEG4.GovLength < options.GovLengthRange.Min)
            {
                config.MPEG4.GovLength = options.GovLengthRange.Min;
            }
            if (options.Mpeg4ProfilesSupported.Length > 0)
            {
                config.MPEG4.Mpeg4Profile = options.Mpeg4ProfilesSupported[0];
            }
            if ((config.RateControl == null) && (framerate.HasValue || bitrate.HasValue))
            {
                config.RateControl = new VideoRateControl();
            }
            if (config.RateControl != null)
            {
                config.RateControl.FrameRateLimit = framerate.HasValue ? framerate.Value : options.FrameRateRange.Max;
                config.RateControl.EncodingInterval = options.EncodingIntervalRange.Min;
                if (bitrate.HasValue)
                {
                    config.RateControl.BitrateLimit = bitrate.Value;
                }
            }
            config.Resolution = resolution;
        }

        public void SetProfiles(TestTool.Proxies.Onvif.Profile[] profiles)
        {
            base.BeginInvoke((Action)delegate
            {
                this.cmbMediaProfile.Items.Clear();
                object item = null;
                foreach (TestTool.Proxies.Onvif.Profile profile in profiles)
                {
                    MediaProfileWrapper wrapper = new MediaProfileWrapper
                    {
                        Profile = profile
                    };
                    object obj3 = wrapper;
                    if (this.IsTestProfile(profile))
                    {
                        item = obj3;
                    }
                    this.cmbMediaProfile.Items.Add(obj3);
                }
                if (item == null)
                {
                    MediaProfileWrapper wrapper2 = new MediaProfileWrapper
                    {
                        Profile = new TestTool.Proxies.Onvif.Profile()
                    };
                    item = wrapper2;
                    ((MediaProfileWrapper)item).Profile.Name = "TestMediaProfile";
                    this.cmbMediaProfile.Items.Add(item);
                }
                this.cmbMediaProfile.SelectedItem = item;
            });
        }

        public void SetVideoEncoderConfigOptions(VideoEncoderConfigurationOptions options)
        {
            base.BeginInvoke((Action)delegate
            {
                this.cmbVideoCodec.Items.Clear();
                if (options.JPEG != null)
                {
                    VideoCodecWrapper item = new VideoCodecWrapper
                    {
                        Jpeg = options.JPEG
                    };
                    this.cmbVideoCodec.Items.Add(item);
                }
                if (options.MPEG4 != null)
                {
                    VideoCodecWrapper wrapper2 = new VideoCodecWrapper
                    {
                        Mpeg4 = options.MPEG4
                    };
                    this.cmbVideoCodec.Items.Add(wrapper2);
                }
                if (options.H264 != null)
                {
                    VideoCodecWrapper wrapper3 = new VideoCodecWrapper
                    {
                        H264 = options.H264
                    };
                    this.cmbVideoCodec.Items.Add(wrapper3);
                }
                if (this.cmbVideoCodec.Items.Count > 0)
                {
                    this.cmbVideoCodec.SelectedIndex = 0;
                }
            });
        }

        public void SetVideoEncoderConfigs(VideoEncoderConfiguration[] configs)
        {
            base.BeginInvoke((Action)delegate
            {
                this.cmbVideoEncoder.Items.Clear();
                foreach (VideoEncoderConfiguration configuration in configs)
                {
                    VideoEncoderConfigurationWrapper item = new VideoEncoderConfigurationWrapper
                    {
                        Configuration = configuration
                    };
                    this.cmbVideoEncoder.Items.Add(item);
                }
                if (this.cmbVideoEncoder.Items.Count > 0)
                {
                    this.cmbVideoEncoder.SelectedIndex = 0;
                }
            });
        }

        public void SetVideoSourceConfigs(VideoSourceConfiguration[] configs)
        {
            base.BeginInvoke((Action)delegate
            {
                this.cmbVideoSource.Items.Clear();
                foreach (VideoSourceConfiguration configuration in configs)
                {
                    VideoSourceConfigurationWrapper item = new VideoSourceConfigurationWrapper
                    {
                        Configuration = configuration
                    };
                    this.cmbVideoSource.Items.Add(item);
                }
                if (this.cmbVideoSource.Items.Count > 0)
                {
                    this.cmbVideoSource.SelectedIndex = 0;
                }
            });
        }

        public void ShowVideo(MediaUri uri, VideoEncoderConfiguration encoder, AudioEncoderConfiguration audio)
        {
            Action method = null;
            try
            {
                this._videoWindow = new VideoContainer();
                DeviceEnvironment deviceEnvironment = ContextController.GetDeviceEnvironment();
                int message = deviceEnvironment.Timeouts.Message;
                TransportProtocol transportProtocol = this.GetTransportProtocol();
                VideoUtils.AdjustVideo(this._videoWindow, deviceEnvironment.Credentials.UserName, deviceEnvironment.Credentials.Password, message, transportProtocol, StreamType.RTPUnicast, uri, encoder);
                this._videoWindow.KEEPALIVE = true;
                this._videoWindow.DebugPage = true;
                this._videoWindow.OpenWindow(audio != null);
                if (method == null)
                {
                    method = () => this.btnGetStreams.Text = "Stop Video";
                }
                base.Invoke(method);
            }
            catch
            {
                this._videoWindow.DebugPage = false;
                this._videoWindow = null;
                throw;
            }
        }

        public override void SwitchToState(TestTool.GUI.Enums.ApplicationState state)
        {
            if (state.IsActive())
            {
                this.EnableControls(false);
            }
            else
            {
                this.EnableControls(true);
            }
        }

        private void txtVideoBitrate_Validating(object sender, CancelEventArgs e)
        {
            int num;
            if (!string.IsNullOrEmpty(this.txtVideoBitrate.Text) && !int.TryParse(this.txtVideoBitrate.Text, out num))
            {
                base.ShowPrompt("Please enter integer value", "Error");
                e.Cancel = true;
            }
        }

        private void txtVideoFramerate_Validating(object sender, CancelEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtVideoFramerate.Text))
            {
                int num;
                IntRange frameLimit = null;
                bool flag = int.TryParse(this.txtVideoFramerate.Text, out num);
                VideoCodecWrapper selectedItem = this.cmbVideoCodec.SelectedItem as VideoCodecWrapper;
                if (selectedItem != null)
                {
                    frameLimit = selectedItem.GetFrameLimit();
                    if ((frameLimit != null) && flag)
                    {
                        flag = (num >= frameLimit.Min) && (num <= frameLimit.Max);
                    }
                }
                if (!flag)
                {
                    string message = "Please enter integer value";
                    if (frameLimit != null)
                    {
                        message = message + string.Format(" between {0} and {1}", frameLimit.Min, frameLimit.Max);
                    }
                    base.ShowPrompt(message, "Error");
                    e.Cancel = true;
                }
            }
        }

        internal MediaController Controller
        {
            get
            {
                return this._controller;
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string MediaAddress
        {
            get
            {
                return this.tbMediaUrl.Text;
            }
            set
            {
                base.BeginInvoke((Action)delegate
                {
                    this.tbMediaUrl.Text = value;
                    this.ClearInfo();
                });
            }
        }

        private class AudioEncoderConfigurationWrapper
        {
            public override string ToString()
            {
                if (string.IsNullOrEmpty(this.Configuration.Name))
                {
                    return this.Configuration.token;
                }
                return string.Format("{0} ({1})", this.Configuration.Name, this.Configuration.token);
            }

            public AudioEncoderConfiguration Configuration { get; set; }
        }

        private class AudioSourceConfigurationWrapper
        {
            public override string ToString()
            {
                if (string.IsNullOrEmpty(this.Configuration.Name))
                {
                    return this.Configuration.token;
                }
                return string.Format("{0} ({1})", this.Configuration.Name, this.Configuration.token);
            }

            public AudioSourceConfiguration Configuration { get; set; }
        }

        private class MediaProfileWrapper
        {
            public override string ToString()
            {
                if (string.IsNullOrEmpty(this.Profile.Name))
                {
                    return this.Profile.token;
                }
                return string.Format("{0} ({1})", this.Profile.Name, this.Profile.token);
            }

            public TestTool.Proxies.Onvif.Profile Profile { get; set; }
        }

        private class TransportProtocolWrapper
        {
            public TransportProtocolWrapper(TransportProtocol value, string text)
            {
                this.Value = value;
                this.Text = text;
            }

            public static implicit operator TransportProtocol(MediaPage.TransportProtocolWrapper item)
            {
                return item.Value;
            }

            public override string ToString()
            {
                return this.Text;
            }

            public string Text { get; set; }

            public TransportProtocol Value { get; set; }
        }

        private class VideoCodecWrapper
        {
            public IntRange GetFrameLimit()
            {
                IntRange frameRateRange = null;
                if (this.H264 != null)
                {
                    return this.H264.FrameRateRange;
                }
                if (this.Jpeg != null)
                {
                    return this.Jpeg.FrameRateRange;
                }
                if (this.Mpeg4 != null)
                {
                    frameRateRange = this.Mpeg4.FrameRateRange;
                }
                return frameRateRange;
            }

            public VideoResolution[] GetResolutions()
            {
                VideoResolution[] resolutionsAvailable = null;
                if (this.H264 != null)
                {
                    return this.H264.ResolutionsAvailable;
                }
                if (this.Jpeg != null)
                {
                    return this.Jpeg.ResolutionsAvailable;
                }
                if (this.Mpeg4 != null)
                {
                    resolutionsAvailable = this.Mpeg4.ResolutionsAvailable;
                }
                return resolutionsAvailable;
            }

            public override string ToString()
            {
                if (this.H264 != null)
                {
                    return "H264";
                }
                if (this.Jpeg == null)
                {
                    return "Mpeg4";
                }
                return "Jpeg";
            }

            public VideoEncoding Encoding
            {
                get
                {
                    if (this.H264 != null)
                    {
                        return VideoEncoding.H264;
                    }
                    if (this.Jpeg == null)
                    {
                        return VideoEncoding.MPEG4;
                    }
                    return VideoEncoding.JPEG;
                }
            }

            public H264Options H264 { get; set; }

            public JpegOptions Jpeg { get; set; }

            public Mpeg4Options Mpeg4 { get; set; }
        }

        private class VideoEncoderConfigurationWrapper
        {
            public override string ToString()
            {
                if (string.IsNullOrEmpty(this.Configuration.Name))
                {
                    return this.Configuration.token;
                }
                return string.Format("{0} ({1})", this.Configuration.Name, this.Configuration.token);
            }

            public VideoEncoderConfiguration Configuration { get; set; }
        }

        private class VideoResolutionWrapper
        {
            public override string ToString()
            {
                if (this.Resolution == null)
                {
                    return string.Empty;
                }
                return string.Format("{0}x{1}", this.Resolution.Width, this.Resolution.Height);
            }

            public VideoResolution Resolution { get; set; }
        }

        private class VideoSourceConfigurationWrapper
        {
            public override string ToString()
            {
                if (string.IsNullOrEmpty(this.Configuration.Name))
                {
                    return this.Configuration.token;
                }
                return string.Format("{0} ({1})", this.Configuration.Name, this.Configuration.token);
            }

            public VideoSourceConfiguration Configuration { get; set; }
        }
    }
}

